<?php
namespace app\admin\controller;

use cmf\controller\AdminBaseController;
use think\Db;

class GameorderController extends AdminBaseController
{
  public function _initialize()
  {
  }
  
  /**商家冠名列表*/
  public function index ()
  {
  
    $where   = [];
    $request = input('request.');
    
    if (!empty($request['uid'])) {
      $where['izy_game_order.uid'] = array('EQ',intval($request['uid']));
    }
    
    if (!empty($request['mobile'])) {
      $query_mobile = $request['mobile'];
      $where['izy_game_order.mobile'] = array('LIKE', "%$query_mobile%");
    }
  
    if (!empty($request['date'])) {
      $query_time = strtotime($request['date']);
      $where['izy_game_order.ctime'] = array('EGT', $query_time);
    }
    
    $list = Db::connect('aizuoyou')
      ->name('game_order')
      ->join('user','izy_game_order.uid = izy_user.uid')
      ->join('ticket', 'izy_game_order.ticketid = izy_ticket.id')
      ->field(array(
        'izy_user.uid',
        'izy_user.truename',
        'izy_user.mobile',
        'izy_game_order.adname',
        'izy_game_order.background',
        'izy_game_order.distance',
        'izy_game_order.days',
        'izy_ticket.price',
        'izy_ticket.used',
        'izy_game_order.money',
        'izy_game_order.returnprofitmoney',
        'izy_game_order.shownum',
        'izy_game_order.ctime',
        'izy_game_order.latitude',
        'izy_game_order.longitude',
        'izy_game_order.sharelink',
      ))
      ->where($where)
      ->order("izy_game_order.ctime DESC")
      ->paginate(10);
    
    // 获取分页显示
    $page = $list->render();
    $this->assign('list', $list);
    $this->assign('page', $page);
    // 渲染模板输出
    return $this->fetch();
  }
  
  /**商家定制续费列表*/
  public function renewal ()
  {
  
    $where   = [];
    $request = input('request.');
  
    if (!empty($request['uid'])) {
      $where['izy_game_order_renewal.uid'] = array('EQ',intval($request['uid']));
    }
  
    if (!empty($request['mobile'])) {
      $query_mobile = $request['mobile'];
      $where['izy_user.mobile'] = array('LIKE', "%$query_mobile%");
    }
  
    if (!empty($request['date'])) {
      $query_time = strtotime($request['date']);
      $where['izy_game_order_renewal.ctime'] = array('EGT', $query_time);
    }
  
    $list = Db::connect('aizuoyou')
      ->name('game_order_renewal')
      ->join('game_order', 'izy_game_order_renewal.orderid = izy_game_order.id')
      ->join('ticket', 'izy_game_order_renewal.ticketid = izy_ticket.id', 'left')
      ->join('user','izy_game_order_renewal.uid = izy_user.uid')
      ->where($where)
      ->field(array(
        'izy_user.uid',
        'izy_user.truename',
        'izy_user.mobile',
        'izy_game_order.adname',
        'izy_game_order.background',
        'izy_game_order.distance',
        'izy_game_order_renewal.days',
        'izy_ticket.price',
        'izy_ticket.used',
        'izy_game_order_renewal.money',
        'izy_game_order_renewal.returnprofitmoney',
        'izy_game_order.shownum',
        'izy_game_order_renewal.ctime',
        'izy_game_order.latitude',
        'izy_game_order.longitude',
        'izy_game_order.sharelink',
      ))
      ->order("izy_game_order_renewal.ctime DESC")
      ->paginate(10);
    
    // 获取分页显示
    $page = $list->render();
    $this->assign('list', $list);
    $this->assign('page', $page);
    // 渲染模板输出
    return $this->fetch();
  }
}